package com.wtwd.campus.hxy.controller;

import com.alibaba.fastjson.JSONObject;
import com.wtwd.campus.hxy.model.vo.ResultVO;
import com.wtwd.campus.hxy.service.HxyClassPatternService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author mjy
 * @date 2021/07/29
 * @description
 */
@RestController
@RequestMapping("/hxy/classPattern")
public class HxyDeviceClassPatternController {

    @Autowired
    private HxyClassPatternService hxyClassPatternService;

    /**
     * 上课免打扰设置接⼝（默认提交过来全量的数据）
     */
    @PostMapping("/setClassPattern")
    public Object setClassPattern(@RequestBody JSONObject jsonObject) {
        String imei = jsonObject.getString("imei");
        //是否隐身 0取消隐身，1开启隐身
        Integer swit = jsonObject.getInteger("swit");
        List<Map> data = jsonObject.getJSONArray("data").toJavaList(Map.class);
        return hxyClassPatternService.setClassPattern(imei, swit, data);
    }

    /**
     * 免打扰时间段列表
     * @param jsonObject
     * @return
     */
    @PostMapping("/getClassPatternList")
    public Object getClassPatternList(@RequestBody JSONObject jsonObject){
        String imei = jsonObject.getString("imei");
        return hxyClassPatternService.getClassPatternList(imei);
    }

}
